﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SGRapidForm.Common;
using SGRapidForm.Permission.Entity;
using FishWebLib;
using System.Collections.Specialized;
using System.Data;

namespace SGRapidForm.Permission.Component
{
    public class ShortcutsComponent : ComponentBase
    {
        public bool Shortcuts_Add(string userKeyid, string pageKeyid)
        {
            return (FishBLLHelper.CallSpExecuteNonQuery("sgrf_permission_Shortcuts_Add", null, userKeyid, pageKeyid) > 0);
        }

        public bool Shortcuts_Delete(string userKeyid, string pageKeyids)
        {
            //Keyid数量
            int count = SqlHelper.GetKeyidsCount(pageKeyids);
            //Keyids转换成Sql语句
            pageKeyids = SqlHelper.ConvertKeyidsToSqlStatement(pageKeyids);
            return (FishBLLHelper.CallSpExecuteNonQuery("sgrf_permission_Shortcuts_Delete", null, userKeyid, pageKeyids) > 0);
        }

        public List<PermissionDetails> Shortcuts_GetAllByUserKeyid(string userKeyid, string filterConditions)
        {
            NameValueCollection fieldCollection = SqlHelper.ParseQueryString(filterConditions);
            StringBuilder sql = new StringBuilder();
            sql.Append(SqlHelper.GenerateSqlStatement(fieldCollection, "PageCode", DbType.String, "AND sgrf_permission_Page.PageCode like '%{0}%'"));
            sql.Append(SqlHelper.GenerateSqlStatement(fieldCollection, "PageName", DbType.String, " AND sgrf_permission_Page.PageName like '%{0}%' "));
            sql.Append(SqlHelper.GenerateSqlStatement(fieldCollection, "ModuleKeyid", DbType.String, " AND sgrf_permission_Page.ModuleKeyid = '{0}' "));
            filterConditions = sql.ToString();

            return FishBLLHelper.CallSpGetDataItemList<PermissionDetails>("sgrf_permission_Shortcuts_GetAllByUserKeyid", null, userKeyid, filterConditions);
        }

        public List<PageEntity> Shortcuts_GetByUserKeyid(string userKeyid)
        {
            return FishBLLHelper.CallSpGetDataItemList<PageEntity>("sgrf_permission_Shortcuts_GetByUserKeyid", null, userKeyid);
        }

        public List<PermissionDetails> Shortcuts_GetListByUserKeyid(string userKeyid, string filterConditions)
        {
            NameValueCollection fieldCollection = SqlHelper.ParseQueryString(filterConditions);
            StringBuilder sql = new StringBuilder();
            sql.Append(SqlHelper.GenerateSqlStatement(fieldCollection, "PageCode", DbType.String, "AND sgrf_permission_Page.PageCode like '%{0}%'"));
            sql.Append(SqlHelper.GenerateSqlStatement(fieldCollection, "PageName", DbType.String, " AND sgrf_permission_Page.PageName like '%{0}%' "));
            sql.Append(SqlHelper.GenerateSqlStatement(fieldCollection, "ModuleKeyid", DbType.String, " AND sgrf_permission_Page.ModuleKeyid = '{0}' "));
            filterConditions = sql.ToString();

            return FishBLLHelper.CallSpGetDataItemList<PermissionDetails>("sgrf_permission_Shortcuts_GetListByUserKeyid", null, userKeyid, filterConditions);
        }
    }
}
